﻿@model RoadFlow.Model.Dictionary
<form method="post">
    @Html.AntiForgeryToken()
    <br />
    <input type="hidden" name="Id" value="@Model.Id" />
    <input type="hidden" name="ParentId" value="@Model.ParentId" />
    <input type="hidden" name="Sort" value="@Model.Sort" />
    <table cellpadding="0" cellspacing="1" border="0" width="95%" class="formtable">
        <tr>
            <th style="width:80px;">标题：</th>
            <td><input type="text" id="Title" name="Title" class="mytext" value="@Model.Title" validate="empty" maxlength="100" style="width:70%" /></td>
        </tr>
        <tr>
            <th style="width:80px;">唯一代码：</th>
            <td><input type="text" id="Code" name="Code" class="mytext" value="@Model.Code" validate="canempty,ajax" validate_url="CheckCode?id=@Model.Id" maxlength="100" style="width:70%" /></td>
        </tr>
        <tr>
            <th style="width:80px;">值：</th>
            <td><input type="text" id="Value" name="Value" class="mytext" value="@Model.Value" maxlength="100" style="width:70%" /></td>
        </tr>
        <tr>
            <th style="width:80px;">备注：</th>
            <td><textarea id="Note" name="Note" class="mytext" style="width:90%; height:80px;">@Html.Raw(Model.Note)</textarea></td>
        </tr>
        <tr>
            <th style="width:80px;">其它：</th>
            <td><textarea id="Other" name="Other" class="mytext" style="width:90%; height:80px;">@Html.Raw(Model.Other)</textarea></td>
        </tr>
        <tr>
            <th style="width:80px;">状态：</th>
            <td>
                <input type="radio" validate="radio" @(Model.Status == 0 ? "checked='checked'" : "") value="0" name="Status" id="Status_0" style="vertical-align:middle;" /><label for="Status_0" style="vertical-align:middle;">正常</label>
                <input type="radio" validate="radio" @(Model.Status == 1 ? "checked='checked'" : "") value="1" name="Status" id="Status_1" style="vertical-align:middle;" /><label for="Status_1" style="vertical-align:middle;">作废</label>
                <span class="validate"></span>
            </td>
        </tr>
    </table>
    <div class="buttondiv">
        <input type="button" class="mybutton" value="&nbsp;保&nbsp;&nbsp;存&nbsp;" onclick="save(this);" />
        @if (ViewData["id"].ToString().Length > 0)
        {
            <input type="button" class="mybutton" value="添加子项" id="addbut" onclick="window.location='Body?parentid=@ViewData["id"]&@ViewData["query"]';" />
            <input type="button" class="mybutton" value="&nbsp;删&nbsp;&nbsp;除&nbsp;" id="delbut" onclick="del(this);" />
            <input type="button" class="mybutton" value="&nbsp;排&nbsp;&nbsp;序&nbsp;" id="sortbut" onclick="sort1();" />
            <input type="button" class="mybutton" value="&nbsp;导&nbsp;&nbsp;出&nbsp;" id="exportbut" onclick="exportDict();" />
            if ("1".Equals(ViewData["isRoot"].ToString()))//根节点显示导入
            {
                <input type="button" class="mybutton" value="&nbsp;导&nbsp;&nbsp;入&nbsp;" id="importbut" onclick="importDict();" />
            }
        }
        else
        {
            <input type="button" class="mybutton" value="&nbsp;返&nbsp;&nbsp;回&nbsp;" id="sortbut" onclick="window.location = 'Body?id=@ViewData["refreshId"]&@Html.Raw(ViewData["query1"])';" />
        }
    </div>
</form>
<script type="text/javascript">
    $(function ()
    {
        
    });
    function sort1()
    {
        window.location = "Sort@(Html.Raw(ViewData["query"]))";
    }
    function save(but)
    {
        var f = document.forms[0];
        if (new RoadUI.Validate().validateForm(f)) {
            var o = RoadUI.Core.serializeForm($(f));
            $(but).prop("disabled", true);
            $.ajax({
                url: "SaveBody@(Html.Raw(ViewData["query"]))", data: o, type: "post", success: function (text) {
                    if (RoadUI.Core.checkLogin(text, false)) {
                        alert(text);
                    }
                    var refreshId = "@ViewData["refreshId"]";
                    if (refreshId.length > 0)
                    {
                        parent.frames[0].reLoad(refreshId);
                    }
                    window.location = "Body@(Html.Raw(ViewData["query"]))";
                    
                }
            });
        }
    }
    function del(but)
    {
        if (!confirm("您真的要删除该字典及其所有下级吗?"))
        {
            return;
        }
        $(but).prop("disabled", true);
        var o = { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() };
        $.ajax({
            url: "DeleteBody@(Html.Raw(ViewData["query"]))", data: o, type: "post", success: function (text) {
                if (RoadUI.Core.checkLogin(text, false)) {
                    alert(text);
                }
                var refreshId = "@ViewData["refreshId"]";
                if (refreshId.length > 0)
                {
                    parent.frames[0].reLoad(refreshId);
                }
                window.location = "Body?id=@ViewData["refreshId"]&@Html.Raw(ViewData["query1"])";
            }
        });
    }
    function exportDict()
    {
        var url = "Export@(Html.Raw(ViewData["query"]))";
        window.location = url;
    }
    function importDict() {
        var url = "Import@(Html.Raw(ViewData["query"]))";
        new RoadUI.Window().open({ title: "导入数据字典", width: 400, height: 200, url: url, opener: window, resize: false });
    }
</script>
